package no.eirikb.bomberman.shared;

import no.eirikb.bomberman.applet.game.Pos;
import no.eirikb.bomberman.applet.game.Way;
import java.io.Serializable;

/**
 *
 * @author eirikb
 */
public class User implements Serializable {

    private String nick;
    private String character;
    private boolean ready;
    private String gameName;
    private Pos pos;  // Used to draw the character at right pixel
    private Pos lastPos;    // Used so the clients know where the user is headein (latencyproblem)
    private boolean walking;
    private double speed;
    private Way way;
    private int anim2;
    private int animWait;
    private int bombs;
    private int bombSize;
    private int bombTime;
    private final int[] anim = {0, 1, 0, 2};

    public User(String nick) {
        this.nick = nick;
        character = "default";
        way = Way.LEFT;
        // May be called by GameHandler anyway...
        speed = 1;
        bombs = 1;
        bombSize = 1;
        bombTime = 3;
    }

    public String getNick() {
        return nick;
    }

    public String getCharacter() {
        return character;
    }

    public boolean isReady() {
        return ready;
    }

    public String getGameName() {
        return gameName;
    }

    public void setNick(String nick) {
        this.nick = nick;
    }

    public void setCharacter(String character) {
        this.character = character;
    }

    public void setReady(boolean ready) {
        this.ready = ready;
    }

    public void setGameName(String gameName) {
        this.gameName = gameName;
    }

    public int getAnim() {
        int a = anim[anim2];
        if (walking || lastPos != null) {
            animWait++;
            if (animWait == 4) {
                anim2 = anim2 == 3 ? 0 : anim2 + 1;
                animWait = 0;
            }
        }
        return a;
    }

    public Way getWay() {
        return way;
    }

    public void setWay(Way way) {
        this.way = way;
    }

    public Pos getPos() {
        return pos;
    }

    public void setPos(Pos pos) {
        this.pos = pos;
    }

    public Pos getLastPos() {
        return lastPos;
    }

    public void setLastPos(Pos lastPos) {
        this.lastPos = lastPos;
    }

    public boolean isWalking() {
        return walking;
    }

    public void setWalking(boolean walking) {
        this.walking = walking;
    }

    public double getSpeed() {
        return speed;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
    }

    public int getBombs() {
        return bombs;
    }

    public void setBombs(int bombs) {
        this.bombs = bombs;
    }

    public int getBombSize() {
        return bombSize;
    }

    public void setBombSize(int bombSize) {
        this.bombSize = bombSize;
    }

    public int getBombTime() {
        return bombTime;
    }

    public void setBombTime(int bombTime) {
        this.bombTime = bombTime;
    }

    @Override
    public String toString() {
        if (ready) {
            return "[X] " + nick;
        } else {
            return "[ ] " + nick;
        }
    }
}
